#include "linktest.h"

/*Registry this TestSuite to theTestFactoryRegistry*/
CPPUNIT_TEST_SUITE_REGISTRATION (LinkTest);

void LinkTest::setUp() {
	SG_init();
}

void LinkTest::testConstructor() {
	Resource *l = NULL;
	try {
	 l = new Link("LinkError", "FakeLat", 0, "FakeBw", 0, "FakeBwLim", 0, "LatError", "BWError");
	CPPUNIT_FAIL("An exception should be throwed!! No file can be opened");
	} catch (std::runtime_error &e) {
//		Pass
	}

}

void LinkTest:: testGetLatBwBwLimFixed() { fprintf(stderr,">>> LinkTest::testGetLatBwBwLimFixed()\n");
	Link *l = NULL;
	 l = new Link("LinkFixed", 0.003, 100, 200);	
	  /**link parameters*/
	 double llat = l->getLatency(0);
	 double lbw = l->getBandwidth(0);	 
	 double lbw_lim = l->getBandwidthLimit(0);	 	 
	 /*To compare*/
	 double lat = 0.003;
	 double bw = 100;
	 double bw_lim = 200;
	 CPPUNIT_ASSERT(llat==lat);
	 CPPUNIT_ASSERT(lbw==bw);
 	 CPPUNIT_ASSERT(lbw_lim==bw_lim);

 	 delete l;	 
}

void LinkTest:: testGetLatBwBwLimTrace() { fprintf(stderr,">>> LinkTest::testGetLatBwBwLimTrace()\n");
	Link *l = NULL;

	 l = new Link ("LinkIntraSite", NULL, 0, "../data/traces/cputrace.0", 0, "../data/traces/cputrace.0", 0, NULL, "../data/traces/cputrace.0");
	 
	  /* link parameters */
	 double llat = l->getLatency(110);
	 double lbw = l->getBandwidth(110);	 
	 double lbw_lim = l->getBandwidthLimit(110);	 	 
	 
	 /* To compare */
	 double lat = Link::MINIMUM_LATENCY;
	 double bw = 0.898850;
	 double bw_lim = 0.898850;
	 
	 CPPUNIT_ASSERT( llat == lat );
	 CPPUNIT_ASSERT( lbw == bw );
 	 CPPUNIT_ASSERT( lbw_lim == bw_lim );	 
 	 
 	 delete l;
 	 
 	 l=NULL;
 	 
	 l = new Link ("LinkIntraSite", NULL, 0, "../data/traces/cputrace.0", 0, "../data/traces/cputrace.0", 0, NULL, "../data/traces/cputrace.0", "../data/traces/cputrace.0", "../data/traces/cputrace.0", "../data/traces/cputrace.0");
 	 
 	 lat  = 0.898850;
	 llat = l->getLatency(110);
	 
	 CPPUNIT_ASSERT( llat == lat );	

	 delete l;
//	SG_simulate(110,NULL, SG_VERBOSE);
//	printf("Trace_Available=%Lf",  l->getBandwidth(-1));		
 	 
}

void LinkTest::testGetType() { fprintf(stderr,">>> LinkTest::testGetType()\n");
	Link *l = new Link ("LinkIntraSite", NULL, 0, "../data/traces/cputrace.0", 0, "../data/traces/cputrace.0", 0, NULL, "../data/traces/cputrace.0", "../data/traces/cputrace.0", "../data/traces/cputrace.0", "../data/traces/cputrace.0");
	CPPUNIT_ASSERT(l->getType()==SG_LINK);	
	delete l;
}

void LinkTest:: tearDown() {
	SG_clear();
}
